home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / virus / stelth22.zip / DOSMCB.C < prev    next >
C/C++ Source or Header  |  1992-02-10  |  2KB  |  97 lines

  1. /*
  2. dosmcb.c
  3. Stealth Bomber Version 2.2
  4.  
  5. Kevin Dean
  6. Fairview Mall P.O. Box 55074
  7. 1800 Sheppard Avenue East
  8. Willowdale, Ontario
  9. CANADA    M2J 5B9
  10. CompuServe ID: 76336,3114
  11.  
  12. February 10, 1992
  13.  
  14.     This module handles the DOS memory control block interface.
  15.  
  16.     This code is public domain.
  17. */
  18.  
  19.  
  20. #if (defined(M_I86SM) || defined(M_I86MM) || defined(M_I86CM) || defined(M_I86LM) || defined(M_I86HM)) && !defined(_MSC_VER) && !defined(_QC)
  21. #define _MSC_VER
  22. #endif
  23.  
  24. #if !defined(__BORLANDC__) && !defined(__TURBOC__) && !defined(_MSC_VER) && !defined(_QC)
  25. #error Unknown compiler.
  26. #endif
  27.  
  28.  
  29. #include <dos.h>
  30. #include <stddef.h>
  31.  
  32. #include "dosmcb.h"
  33.  
  34.  
  35. #if defined(_MSC_VER) || defined(_QC)
  36.  
  37. #if !defined(MK_FP)
  38. #define MK_FP(seg, off)  ((void far *)(((unsigned long)(seg) << 16) | (off)))
  39. #endif
  40.  
  41. #if !defined(peek)
  42. #define peek(seg, off)  (*(int far *)MK_FP(seg, off))
  43. #endif
  44.  
  45. #endif
  46.  
  47.  
  48. /***/
  49. /* Get the first DOS memory control block. */
  50. MCB far *getmcb(void)
  51. {
  52. union REGS regs;
  53. struct SREGS sregs;
  54.  
  55. /* DOS function 0x52 gets the DOS list of lists. */
  56. regs.h.ah = 0x52;
  57. segread(&sregs);
  58. intdosx(®s, ®s, &sregs);
  59.  
  60. /* The first MCB segment pointer is two bytes behind the list of lists. */
  61. return (MK_FP(peek(sregs.es, regs.x.bx - 2), 0));
  62. }
  63.  
  64.  
  65. /***/
  66. /* Get the next DOS memory control block. */
  67. MCB far *nextmcb(MCB far *thismcb)
  68. {
  69. /* Next MCB is size + 1 paragraphs away. */
  70. return (thismcb->id == 0x5A ? NULL : MK_FP(FP_SEG(thismcb) + thismcb->size + 1, 0));
  71. }
  72.  
  73.  
  74. /***/
  75. /* Determine the owner of a particular pointer. */
  76. MCB far *mcb_owner(const void far *ptr)
  77. {
  78. /* Determine true segment. */
  79. unsigned pseg = FP_SEG(ptr) + (FP_OFF(ptr) >> 4);
  80.  
  81. MCB far *mcb = getmcb();
  82.  
  83. /* Pointer is invalid if below DOS memory or has wrapped around high memory. */
  84. if (pseg < FP_SEG(mcb) || pseg < FP_SEG(ptr))
  85.   mcb = NULL;
  86.  
  87. /* Find pointer's MCB if it exists. */
  88. while (mcb && pseg > FP_SEG(mcb) + mcb->size)
  89.   mcb = nextmcb(mcb);
  90.  
  91. /* Pointer cannot point within MCB itself. */
  92. if (pseg == FP_SEG(mcb))
  93.   mcb = NULL;
  94.  
  95. return (mcb);
  96. }
  97.